<?
$params["id"] = 1;
global $db;
$e = $db->query1("select * from node where id = ".$db->sqlint($params["id"]));
$e["title"] = "Tags";
skin_param("page",$e);

$value = $params["fname"];
$value = htmlentities($value);

$tag = $db->sqlstring($value);
$r = $db->query("select t2.* , count(*) as cnt from tags t1, tags t2 where t1.value = $tag and t2.project_id = t1.project_id and t2.value != $tag group by t2.value order by cnt desc limit 24");
inc_inclib("tags.php");
tags_cloud($r); 

echo "<h2>$value</h2>";
echo "<div>{$e["content"]}</div>";



// echo "<p>projects | <a href='releases.php'>recent releases</a></p>";

$start = intval(isset($_REQUEST["start"])?$_REQUEST["start"]:0);
$limit = 24;


$r = $db->query("select project.* from project,tags ".
	" where value = ".$db->sqlstring($value).
	" and project.id = project_id group by project_id ". 
	" order by datetimeon desc limit $start,$limit".
	""); 

inc_inclib("image.php");
global $topdir,$topurl;

ob_start();
echo "<p>";
if ($start!=0) {
    $v = $start-$limit;
    echo "<a href='$topurl/tags/$value?start=$v'>Previous</a> ";
}
for ($v = $limit; $v<=$start; $v+=$limit) {
    $n = $v/$limit;
    echo "<a href='$topurl/tags/$value?start=$v'>$n</a> ";
}
if (count($r)==$limit) {
    $v = $start+$limit;
    echo "<a href='$topurl/tags/$value?start=$v'>Next</a>";
}
echo "</p>";
$nav = ob_get_contents();
ob_end_flush();

echo "<table>";
foreach ($r as $e) {
	echo "<tr>";
	echo "<td valign=top align=center>";
	
	echo "<a href=\"$topurl/project/{$e["id"]}/\">";
	$fname = "$topdir/shots/{$e["image"]}";
	if ($e["image"] != "" && file_exists($fname)) {
	$img = image_thumb($fname,124,93,"jpg",50);
	list($iw,$ih) = getimagesize("$topdir/thumb/$img");
	echo "<img src='$topurl/thumb/$img' width=$iw height=$ih>";
	} else echo "<img src='$topurl/content/noimage.gif' width=124 height=93>";
	echo "</a>";
	
	echo "<td valign=top>";
	
	echo "<a href=\"$topurl/project/{$e["id"]}/\">{$e["title"]}</a><br>";
	echo "{$e["summary"]}";
	
	echo "<tr><td>&nbsp;";
	
	}
echo "</table>";

echo $nav;
?>